<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客资id" prop="kzId">
        <el-input v-model="queryParams.kzId" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户姓名" prop="kzName">
        <el-input v-model="queryParams.kzName" placeholder="请输入客户姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商家名称" prop="shopname">
        <el-input v-model="queryParams.shopname" placeholder="请输入商家名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商家电话" prop="shoptel">
        <el-input v-model="queryParams.shoptel" placeholder="请输入商家名称" clearable @keyup.enter.native="handleQuery"
          onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" />
      </el-form-item>
      <el-form-item label="交易时间">
        <el-date-picker v-model="queryParams.startTime" type="date" value-format="timestamp"
          :picker-options="startDatePicker" placeholder="开始时间" style="width: 180px">
        </el-date-picker>
        <el-date-picker v-model="endTimes" type="date" value-format="timestamp" :picker-options="endDatePicker"
          placeholder="结束时间" style="width: 180px">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:user:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="flowList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="客资id" align="center" prop="kzId" />
      <el-table-column label="订单编号" align="center" prop="ordernum" />
      <el-table-column label="客户姓名" align="center" prop="kzName" />
      <el-table-column label="商家名称" align="center" prop="shopname" />
      <el-table-column label="商家负责人" align="center" prop="shopuser" />
      <el-table-column label="商家电话" align="center" prop="shoptel" />
      <el-table-column label="拍摄种类" align="center" prop="serveType" />
      <el-table-column label="平台扣费" align="center" prop="pfChange" />
      <el-table-column label="成交交易金额" align="center" prop="successmoney" />
      <el-table-column label="交易时间" align="center" prop="pfTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pfTime, '{YY}-{MM}-{DD} {hh}:{mm}:{ss}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>
    
<script>
import { selectOneZkwlShopLsPCcj, selectZkwlShopLsPCcj, daochuExcelchengjiao } from "@/api/business/finace.js";
export default {
  name: "Deal",
  data() {
    return {
      endTimes: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      flowList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        kzId: "",
        kzName: "",
        shopname: "",
        startTime: "",
        endTime: "",
        shoptel: '',
      },
      startDatePicker: this.beginDate(),
      endDatePicker: this.processDate(),
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客资交易明细列表 */
    getList() {
      this.loading = true;
      selectZkwlShopLsPCcj(this.queryParams).then(response => {
        if (response.code == 200) {
          this.flowList = response.rows;
          this.loading = false;
          this.total = response.total;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.queryParams.startTime == '' && this.endTimes == "") {
        selectZkwlShopLsPCcj(this.queryParams).then(response => {
          this.flowList = response.rows;
          this.total = response.total;
        })
      } else if (this.queryParams.startTime == "" && this.endTimes != '') {
        this.$modal.msgError("请输入开始时间");
      } else if (this.queryParams.startTime != '' && this.endTimes == '') {
        this.$modal.msgError("请输入结束时间");
      } else if (this.queryParams.startTime != '' && this.endTimes != '' && this.queryParams.startTime > this.endTimes) {
        this.$modal.msgError("结束时间必须大于开始时间");
      } else if (this.queryParams.startTime != '' && this.endTimes != '' && this.queryParams.startTime < this.endTimes) {
        this.queryParams.endTime = this.endTimes + 24 * 60 * 60 * 1000 - 1;
        selectZkwlShopLsPCcj(this.queryParams).then(response => {
          this.flowList = response.rows;
          this.total = response.total;
        })
      } else if (this.queryParams.startTime == this.queryParams.endTime) {
        this.$modal.msgError("结束时间必须大于开始时间");
      }

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        kzId: "",
        kzName: "",
        shopname: "",
        startTime: "",
        endTime: "",
        shoptel: '',
      };
      this.endTimes = "";
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pfId)
      this.single = selection.length !== 1

    },
    // 验证搜索框日期
    beginDate() {
      const self = this;
      return {
        disabledDate(time) {
          //           debugger;
          if (self.endTime) {
            //如果结束时间不为空，则小于结束时间
            return new Date(self.endTime).getTime() < time.getTime();
          } else {
            return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
          }
        },
      };
    },
    processDate() {
      const self = this;
      return {
        disabledDate(time) {
          if (self.startTime) {
            //如果开始时间不为空，则结束时间大于开始时间
            return new Date(self.startTime).getTime() > time.getTime();
          } else {
            return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
          }
        },
      };
    },
    async handleExport() {
      // this.$confirm('是否确认导出所有用户数据项?', "警告", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning"
      // }).then(function () {
      //   return daochuExcelchengjiao();
      // }).then(response => {
      //   this.$download.name(response.msg);
      // }).catch(function () { });

      const queryParams = this.queryParams;
      let res = await daochuExcelchengjiao(queryParams);
      if (res.code == 200) {
        this.isloading = false;
        this.$download.name(res.msg);
      }
    }
  }
};
</script>
    